package com.jerry.base.io.file;

import lombok.extern.slf4j.Slf4j;
import org.junit.Test;

import java.io.File;

/**
 * Created with IntelliJ IDEA
 * User: Jerry
 * Date: 2024/1/22
 * Time: 21:25
 * Description:
 */
@Slf4j
public class Directory {

    @Test
    public void delete() {
        String filePath = "src/main/resources/io/delete.txt";
        File file = new File(filePath);
        if (file.exists()) {
            log.info("文件存在，进行删除。");
            if (file.delete()) {
                log.info("删除成功！");
            } else {
                log.info("删除失败！");
            }
        } else {
            log.info("文件不存在。");
        }
    }

    @Test
    public void mkDir() {
        String dirPath = "src/main/resources/io/dir/mkDir";
        File dir = new File(dirPath);
        if (dir.exists()) {
            log.info(dirPath + " 目录已存在！");
        } else {
            log.info(dirPath + " 目录不存在，进行创建。");
            if (dir.mkdirs()) {
                log.info(dirPath + " 目录创建成功！");
            } else {
                log.info(dirPath + " 目录创建失败！");
            }
        }
    }

}
